package com.ruoyi.project.lesson.course.service.impl;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.text.Convert;
import com.ruoyi.framework.aspectj.lang.annotation.DataSource;
import com.ruoyi.framework.aspectj.lang.enums.DataSourceType;
import com.ruoyi.project.common.service.ICommonService;
import com.ruoyi.project.lesson.course.domain.LessonCourse;
import com.ruoyi.project.lesson.course.mapper.LessonCourseMapper;
import com.ruoyi.project.lesson.course.service.ILessonCourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 课程章节Service业务层处理
 *
 * @author shixiangwen
 * @date 2020-12-07
 */
@Service
@DataSource(DataSourceType.KKFORMULA)
public class LessonCourseServiceImpl implements ILessonCourseService {

    @Autowired
    private LessonCourseMapper lessonCourseMapper;

    @Autowired
    ICommonService commonService;

    /**
     * 查询课程章节
     *
     * @param id 课程章节ID
     * @return 课程章节
     */
    @Override
    public LessonCourse selectLessonCourseById(Long id) {
        return lessonCourseMapper.selectLessonCourseById(id);
    }

    /**
     * 查询课程章节列表
     *
     * @param lessonCourse 课程章节
     * @return 课程章节
     */
    @Override
    public List<LessonCourse> selectLessonCourseList(LessonCourse lessonCourse) {
        return lessonCourseMapper.selectLessonCourseList(lessonCourse);
    }

    /**
     * 新增课程章节
     *
     * @param lessonCourse 课程章节
     * @return 结果
     */
    @Override
    public int insertLessonCourse(LessonCourse lessonCourse) {
        lessonCourse.setCreatedTime(DateUtils.getNowDate());
        return lessonCourseMapper.insertLessonCourse(lessonCourse);
    }

    /**
     * 修改课程章节
     *
     * @param lessonCourse 课程章节
     * @return 结果
     */
    @Override
    public int updateLessonCourse(LessonCourse lessonCourse) {
        return lessonCourseMapper.updateLessonCourse(lessonCourse);
    }

    /**
     * 删除课程章节对象
     *
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteLessonCourseByIds(String ids) {
        return lessonCourseMapper.deleteLessonCourseByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除课程章节信息
     *
     * @param id 课程章节ID
     * @return 结果
     */
    @Override
    public int deleteLessonCourseById(Long id) {
        return lessonCourseMapper.deleteLessonCourseById(id);
    }

    @Override
    public int getMaxSort(Long id) {
        return commonService.selectTableColumnMaxValue("lesson_course", "sort", " lesson_id = " + id) + 1;
    }
}
